//
//  BaseTabBarController.m
//  ChineseCollegeStudentsNetwork
//
//  Created by 魏苏扬 on 2018/8/8.
//  Copyright © 2018年 刘喆. All rights reserved.
//

#import "BaseTabBarController.h"
#import "HomePageViewController.h"
#import "ConsultationViewController.h"
#import "MagazineViewController.h"
#import "BaseNavigationController.h"
#import "UserCenterViewController.h"

@interface BaseTabBarController ()

@end

@implementation BaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViewControllers];
    
    self.tabBar.translucent = NO;
    // Do any additional setup after loading the view.
}
- (void)setupViewControllers {
    HomePageViewController *news = [[HomePageViewController alloc] init];
    [self addChildViewController:news title:@"首页" image:@"home_unselected" selImage:@"home_selected" isImagePath:NO];
    
    ConsultationViewController *news2 = [[ConsultationViewController alloc] init];
    [self addChildViewController:news2 title:@"咨讯" image:@"consult_unselected" selImage:@"consult_selected" isImagePath:NO];

    
    MagazineViewController *news3 = [[MagazineViewController alloc] init];
    [self addChildViewController:news3 title:@"杂志" image:@"magazine_unselected" selImage:@"magazine_selected" isImagePath:NO];

    UserCenterViewController *news4 = [[UserCenterViewController alloc] init];
    [self addChildViewController:news4 title:@"我的" image:@"mine_unselected" selImage:@"mine_selected" isImagePath:NO];
//    MineViewController *news4 = [[MineViewController alloc] init];
//    [self addChildViewController:news4 title:@"我的" image:@"mine_unselected" selImage:@"mine_selected" isImagePath:NO];
}
-(void)addChildViewController:(UIViewController *)childVC  title:(NSString *)title image:(NSString *)image selImage:(NSString *)selImage isImagePath:(BOOL)isImagePath{
    childVC.title = title;
    if (isImagePath) {
        childVC.tabBarItem.image = [[UIImage imageWithContentsOfFile:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        childVC.tabBarItem.selectedImage = [[UIImage imageWithContentsOfFile:selImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    else{
        childVC.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        childVC.tabBarItem.selectedImage = [[UIImage imageNamed:selImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    childVC.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -3);
    childVC.tabBarItem.imageInsets = UIEdgeInsetsMake(-3, 0, 3, 0);
    
    [childVC.tabBarItem setTitleTextAttributes:@{
                                                 NSFontAttributeName: [UIFont systemFontOfSize:12],
                                                 NSForegroundColorAttributeName: UIColorFromRGBHex(0x326fb8)
                                                 }
                                      forState:UIControlStateSelected];
    [childVC.tabBarItem setTitleTextAttributes:@{
                                                 NSFontAttributeName: [UIFont systemFontOfSize:12],
                                                 NSForegroundColorAttributeName: UIColorFromRGBHex(0x666666)
                                                 }
                                      forState:UIControlStateNormal];
    
    BaseNavigationController *nav = [[BaseNavigationController alloc] initWithRootViewController:childVC];
    [self addChildViewController:nav];
    [childVC viewDidLoad];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
